﻿namespace NOAH.CMS.Repository
{
    using System;
    using System.Collections.Generic;
    using System.Linq;



    public class StaffRepository : Repository<Staff>
    {
        public List<Staff> GetStaffByDepartment(int id)
        {
            if (id == 0) return GetAll().OrderBy(p => p.Name).ToList();
            return GetTable().Where(p => p.DepartmentID == id).OrderBy(p => p.Name).ToList();
        }

        //public List<vwStaffDetail> GetStaffDetailByDepartment(int id)
        //{
        //    if (id == 0) return dataContext.vwStaffDetails.OrderBy(p => p.Name).ToList();
        //    return dataContext.vwStaffDetails.Where(p => p.DepartmentID == id).OrderBy(p => p.Name).ToList();
        //}

        public Staff GetStaffByUsername(string userName)
        {
            return GetTable().Where(p => p.Username == userName).FirstOrDefault();
        }

        public void Delete(string userName)
        {
            Staff staff = GetTable().Where(p => p.Username == userName).FirstOrDefault();
            if (staff != null) base.Delete(staff.ID);
        }
    }
}

